import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'stressSceneTestM',
  state: {},
  effects: {
    //压力测试表格 stressTest/getStressTestList
    *getStressTestList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressSceneTest.getStressTestList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback(false);
        message.error(res?.msg || '查询失败!');
      }
    },
    //资产流动性表格 stressTest/getAssetsFluidityList
    *getAssetsFluidityList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressSceneTest.getAssetsFluidityList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback(false);
        message.error(res?.msg || '查询失败!');
      }
    },

    //投资者赎回 stressTest/getInvestorRedemptionList
    *getInvestorRedemptionList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressSceneTest.getInvestorRedemptionList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback(false);
        message.error(res?.msg || '查询失败!');
      }
    },
    //  查询产品获取最近有持仓的日期
    *findProductTime({ payload, callback }, { call, put }) {
      const res = yield call(api.stressSceneTest.findProductTime, payload);
      if (res && res.data && res.code == 0) {
        callback(res.data.endDate);
      } else {
        message.error(res?.msg);
      }
    },
    //  获取个券下拉列表
    *getBondList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressSceneTest.getBondList, payload);
      if (res && res.data && res.code == 0) {
        res.data.columns = [
          { dataIndex: 'assetType', title: '资产类别', key: 'assetType' },
          { dataIndex: 'tradingCode', title: '证券代码', key: 'tradingCode' },
          { dataIndex: 'tradingName', title: '证券名称', key: 'tradingName' },
          { dataIndex: 'fullValue', title: '全价市值', key: 'fullValue' },
          { dataIndex: 'expectYieldLoss', title: '预期收益率曲线上移(BP)', key: 'expectYieldLoss' },
          { dataIndex: 'expectBondLoss', title: '预期违约率(%)', key: 'expectBondLoss' },
          { dataIndex: 'expectIndexLoss', title: '指数下跌幅度(%)', key: 'expectIndexLoss' },
        ];
        callback(res.data);
      } else {
        message.error(res?.msg);
      }
    },
    //  根据个券计算压力测试结果
    *getBondStressTestList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressSceneTest.getBondStressTestList, payload);
      if (res && res.data && res.code == 0) {
        callback(res.data);
      } else {
        message.error(res?.msg);
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
